<?php require_once('../Connections/aciitu.php'); ?>
<?php
// Load the common classes
require_once('../includes/common/KT_common.php');

// Load the required classes
require_once('../includes/tfi/TFI.php');
require_once('../includes/tso/TSO.php');
require_once('../includes/nav/NAV.php');

// Make unified connection variable
$conn_aciitu = new KT_connection($aciitu, $database_aciitu);

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

// Filter
$tfi_listRsFotos1 = new TFI_TableFilter($conn_aciitu, "tfi_listRsFotos1");
$tfi_listRsFotos1->addColumn("descricao", "STRING_TYPE", "descricao", "%");
$tfi_listRsFotos1->addColumn("caminho", "STRING_TYPE", "caminho", "%");
$tfi_listRsFotos1->addColumn("nome", "STRING_TYPE", "nome", "%");
$tfi_listRsFotos1->Execute();

// Sorter
$tso_listRsFotos1 = new TSO_TableSorter("RsFotos", "tso_listRsFotos1");
$tso_listRsFotos1->addColumn("descricao");
$tso_listRsFotos1->addColumn("caminho");
$tso_listRsFotos1->addColumn("nome");
$tso_listRsFotos1->setDefault("galeria DESC");
$tso_listRsFotos1->Execute();

// Navigation
$nav_listRsFotos1 = new NAV_Regular("nav_listRsFotos1", "RsFotos", "../", $_SERVER['PHP_SELF'], 20);

if (isset($_GET['NxT_id'])) {
  $NxTDetailCond__RsFotos_cond = " conteudo_galeria.galeria = " . GetSQLValueString($_GET['NxT_id'], "int") . " ";
}

//NeXTenesio3 Special List Recordset
$maxRows_RsFotos = $_SESSION['max_rows_nav_listRsFotos1'];
$pageNum_RsFotos = 0;
if (isset($_GET['pageNum_RsFotos'])) {
  $pageNum_RsFotos = $_GET['pageNum_RsFotos'];
}
$startRow_RsFotos = $pageNum_RsFotos * $maxRows_RsFotos;

// Defining List Recordset variable
$NxTDetailCond_RsFotos = "1=1";
if (isset($NxTDetailCond__RsFotos_cond)) {
  $NxTDetailCond_RsFotos = $NxTDetailCond__RsFotos_cond;
}
// Defining List Recordset variable
$NXTFilter_RsFotos = "1=1";
if (isset($_SESSION['filter_tfi_listRsFotos1'])) {
  $NXTFilter_RsFotos = $_SESSION['filter_tfi_listRsFotos1'];
}
// Defining List Recordset variable
$NXTSort_RsFotos = "galeria DESC";
if (isset($_SESSION['sorter_tso_listRsFotos1'])) {
  $NXTSort_RsFotos = $_SESSION['sorter_tso_listRsFotos1'];
}
mysql_select_db($database_aciitu, $aciitu);

$query_RsFotos = "SELECT conteudo_galeria.id, conteudo_galeria.galeria, conteudo_galeria.descricao, conteudo_galeria.caminho, status.nome FROM (conteudo_galeria LEFT JOIN status ON status.id=conteudo_galeria.status) WHERE  status <> 3 AND  {$NxTDetailCond_RsFotos}   ORDER BY id DESC";
$query_limit_RsFotos = sprintf("%s LIMIT %d, %d", $query_RsFotos, $startRow_RsFotos, $maxRows_RsFotos);
$RsFotos = mysql_query($query_limit_RsFotos, $aciitu) or die(mysql_error());
$row_RsFotos = mysql_fetch_assoc($RsFotos);

if (isset($_GET['totalRows_RsFotos'])) {
  $totalRows_RsFotos = $_GET['totalRows_RsFotos'];
} else {
  $all_RsFotos = mysql_query($query_RsFotos);
  $totalRows_RsFotos = mysql_num_rows($all_RsFotos);
}
$totalPages_RsFotos = ceil($totalRows_RsFotos/$maxRows_RsFotos)-1;
//End NeXTenesio3 Special List Recordset

$NxTMasterId_rsgaleria1 = "-1";
if (isset($_GET['NxT_id'])) {
  $NxTMasterId_rsgaleria1 = $_GET['NxT_id'];
}
mysql_select_db($database_aciitu, $aciitu);
$query_rsgaleria1 = sprintf("SELECT id, titulo FROM galeria WHERE id = %s", GetSQLValueString($NxTMasterId_rsgaleria1, "int"));
$rsgaleria1 = mysql_query($query_rsgaleria1, $aciitu) or die(mysql_error());
$row_rsgaleria1 = mysql_fetch_assoc($rsgaleria1);
$totalRows_rsgaleria1 = mysql_num_rows($rsgaleria1);

$nav_listRsFotos1->checkBoundries();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
-->
</style>

<!--lightbox-->
<script type="text/javascript" src="../ferramentas/lightbox/js/prototype.js"></script>
<script type="text/javascript" src="../ferramentas/lightbox/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="../ferramentas/lightbox/js/lightbox.js"></script>
<link rel="stylesheet" href="../ferramentas/lightbox/css/lightbox.css" type="text/css" media="screen" />
<!--fim lightbox-->

<!-- TinyMCE 
<script type="text/javascript" src="../ferramentas/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>
-->

<link href="../css/css_admin.css" rel="stylesheet" type="text/css" />
<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="../includes/common/js/base.js" type="text/javascript"></script>
<script src="../includes/common/js/utility.js" type="text/javascript"></script>
<script src="../includes/skins/style.js" type="text/javascript"></script>
<script src="../includes/nxt/scripts/list.js" type="text/javascript"></script>
<script src="../includes/nxt/scripts/list.js.php" type="text/javascript"></script>
<script type="text/javascript">
$NXT_LIST_SETTINGS = {
  duplicate_buttons: false,
  duplicate_navigation: false,
  row_effects: true,
  show_as_buttons: true,
  record_counter: true
}
</script>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="texto_barra">
  <tr>
    <td>
      <div class="KT_tng" id="listRsFotos1">
        <h1> FOTOS DA GALERIA
          <?php
  $nav_listRsFotos1->Prepare();
  require("../includes/nav/NAV_Text_Statistics.inc.php");
?>
        </h1>
        <div class="KT_tnglist">
          <?php 
// Show IF Conditional region2 
if (isset($_GET['NxT_id'])) {
?>
            <table width="100%">
              <tr class="KT_masterlink">
                <td width="90%"><strong><?php echo $row_rsgaleria1['titulo']; ?></strong></td>
                <td align="right" width="10%"><a href="../includes/nxt/back.php?KT_back=-2">VOLTAR</a></td>
              </tr>
            </table>
            <?php } 
// endif Conditional region2
?>
<form action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>" method="post" id="form1">
            <div class="KT_options"> <a href="<?php echo $nav_listRsFotos1->getShowAllLink(); ?>"><?php echo NXT_getResource("Show"); ?>
              <?php 
  // Show IF Conditional region1
  if (@$_GET['show_all_nav_listRsFotos1'] == 1) {
?>
                <?php echo $_SESSION['default_max_rows_nav_listRsFotos1']; ?>
                <?php 
  // else Conditional region1
  } else { ?>
                <?php echo NXT_getResource("all"); ?>
                <?php } 
  // endif Conditional region1
?>
              <?php echo NXT_getResource("records"); ?></a> &nbsp;
            &nbsp; </div>
            <table cellpadding="2" cellspacing="0" class="KT_tngtable">
              <thead>
                <tr class="KT_row_order">
                  <th> <input type="checkbox" name="KT_selAll" id="KT_selAll"/>
                  </th>
                  <th id="descricao" class="KT_sorter KT_col_descricao <?php echo $tso_listRsFotos1->getSortIcon('descricao'); ?>"> <a href="<?php echo $tso_listRsFotos1->getSortLink('descricao'); ?>">Descricao</a> </th>
                  <th id="caminho" class="KT_sorter KT_col_caminho <?php echo $tso_listRsFotos1->getSortIcon('caminho'); ?>"> <a href="<?php echo $tso_listRsFotos1->getSortLink('caminho'); ?>">Foto</a> </th>
                  <th id="nome" class="KT_sorter KT_col_nome <?php echo $tso_listRsFotos1->getSortIcon('nome'); ?>"> <a href="<?php echo $tso_listRsFotos1->getSortLink('nome'); ?>">Status</a> </th>
                  <th>&nbsp;</th>
                </tr>
              </thead>
              <tbody>
                <?php if ($totalRows_RsFotos == 0) { // Show if recordset empty ?>
                  <tr>
                    <td colspan="5"><?php echo NXT_getResource("The table is empty or the filter you've selected is too restrictive."); ?></td>
                  </tr>
                  <?php } // Show if recordset empty ?>
                <?php if ($totalRows_RsFotos > 0) { // Show if recordset not empty ?>
                  <?php do { ?>
                    <tr class="<?php echo @$cnt1++%2==0 ? "" : "KT_even"; ?>">
                      <td><input type="checkbox" name="kt_pk_conteudo_galeria" class="id_checkbox" value="<?php echo $row_RsFotos['id']; ?>" />
                        <input type="hidden" name="id" class="id_field" value="<?php echo $row_RsFotos['id']; ?>" /></td>
                      <td><div class="KT_col_descricao"><?php echo KT_FormatForList($row_RsFotos['descricao'], 20); ?></div></td>
                      <td>
                      <?php if($row_RsFotos['caminho'] <> ""){ ?>
                      <a href="../arquivos/<?php echo $row_RsFotos['caminho']; ?>" rel="lightbox" title="<?php echo $row_RsFotos['descricao']; ?>">
                      <img src="../imagens/icones/zoom.png" border="0" title="Ver Imagem">
                      </a>
                      <?php } else { ?>
                      <img src="../imagens/icones/no_foto.png" border="0" title="Sem Imagem">
                      <?php } ?>                         
                      </td>
                      <td><div class="KT_col_nome"><?php echo KT_FormatForList($row_RsFotos['nome'], 20); ?></div></td>
                      <td><a class="KT_edit_link" href="Admin_Editar_Fotos.php?<?php echo isset($_GET['NxT_id']) ? "NxT_id=".$_GET['NxT_id'] : ""; ?>&id=<?php echo $row_RsFotos['id']; ?>&KT_back=1"><?php echo NXT_getResource("edit_one"); ?></a> <a class="KT_delete_link" href="#delete"><?php echo NXT_getResource("delete_one"); ?></a></td>
                    </tr>
                    <?php } while ($row_RsFotos = mysql_fetch_assoc($RsFotos)); ?>
                  <?php } // Show if recordset not empty ?>
              </tbody>
            </table>
            <div class="KT_bottomnav">
              <div>
                <?php
            $nav_listRsFotos1->Prepare();
            require("../includes/nav/NAV_Text_Navigation.inc.php");
          ?>
              </div>
            </div>
            <div class="KT_bottombuttons">
              <div class="KT_operations"> <a class="KT_edit_op_link" href="#" onClick="nxt_list_edit_link_form(this); return false;"><?php echo NXT_getResource("edit_all"); ?></a> <a class="KT_delete_op_link" href="#" onClick="nxt_list_delete_link_form(this); return false;"><?php echo NXT_getResource("delete_all"); ?></a> </div>
              <span>&nbsp;</span>
              <select name="no_new" id="no_new">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="10">10</option>
                <option value="15">15</option>
                <option value="20">20</option>
                <option value="50">50</option>
              </select>
<a class="KT_additem_op_link" href="Admin_Editar_Fotos.php?<?php echo isset($_GET['NxT_id']) ? "NxT_id=".$_GET['NxT_id'] : ""; ?>&KT_back=1" onClick="return nxt_list_additem(this)"><?php echo NXT_getResource("add new"); ?></a> </div>
          </form>
        </div>
        <br class="clearfixplain" />
      </div>
	</td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result($RsFotos);

mysql_free_result($rsgaleria1);
?>
